<!--Copyright (C) Kherty.  All rights reserved.-->
<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:oui="http://schemas.Kherty.com/office/2007"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:ss="http://schemas.Kherty.com/office/2007/spreadsheet" 
    xmlns:ssui="clr-namespace:OpenLS.Spreadsheet.UI" 
    xmlns:Internals="clr-namespace:OpenLS.Spreadsheet.UI.Internals" 
    xmlns:Internals1="clr-namespace:OpenLS.UI.Internals;assembly=OpenLS.UI"
    xmlns:Resources="clr-namespace:OpenLS.Spreadsheet.UI.Internals.Resources"
    x:Class="OpenLS.Spreadsheet.UI.WorksheetTabResources"

    >
    <HierarchicalDataTemplate DataType="{x:Type ss:Worksheet}" x:Key="worksheetTabTemplate">
        <Grid >
            <TextBox Text="{Binding Name}" Background="Transparent" Padding="0" FontWeight="Bold" 
               KeyDown="OnTabTextKeyDown" AcceptsReturn="False"  Margin="-2 0 0 0"
                 LostFocus="OnTabTextLostFocus" Visibility="Hidden" Name="textBox" BorderThickness="0"/>
            <TextBlock Text="{Binding Name}"  Background="Transparent"  Padding="0" PreviewMouseDown="OnTabTextPreviewMouseDown" Name="textBlock"/>
        </Grid>
    </HierarchicalDataTemplate>
    <ContextMenu oui:RibbonElement.ControlState="Medium"
                 x:Key="{x:Static ss:SpreadsheetWindowComponents.DefaultSheetTabsContextMenuKey}"
                 >
        <ContextMenu.Resources>
            <Style TargetType="{x:Type MenuItem}" BasedOn="{StaticResource {x:Type MenuItem}}">
                <Style.Triggers>
                    <Trigger Property="IsEnabled" Value="False">
                        <Setter Property="Visibility" Value="Collapsed"></Setter>
                    </Trigger>
                </Style.Triggers>
            </Style>
        </ContextMenu.Resources>
        <MenuItem Header="{x:Static Internals1:UIStringTable.Insert}" Command="{x:Static ssui:SpreadsheetCommands.InsertWorksheet}" CommandParameter ="{Binding}"/>
        <MenuItem Header="{x:Static Resources:UIStringTable.Delete}" Command="{x:Static ssui:SpreadsheetCommands.DeleteSheet}" CommandParameter ="{Binding}"/>
        <MenuItem Header="{x:Static Resources:UIStringTable.Rename}"
                                              CommandParameter ="{Binding}"  
                                              Command="{x:Static ssui:SpreadsheetCommands.RenameWorksheet}"  >
            <MenuItem.CommandBindings>
                <CommandBinding Command="{x:Static ssui:SpreadsheetCommands.RenameWorksheet}" Executed="OnRenameWorksheet" CanExecute="OnCanRenameWorksheet"></CommandBinding>
            </MenuItem.CommandBindings>
        </MenuItem>
        <MenuItem Command="{x:Static ssui:SpreadsheetCommands.MoveOrCopySheet}" CommandParameter ="{Binding}"/>
        <Separator/>
        <MenuItem Command="{x:Static ssui:SpreadsheetCommands.ProtectSheet}"  CommandParameter ="{Binding}"/>
        <MenuItem Command="{x:Static ssui:SpreadsheetCommands.UnprotectSheet}"  CommandParameter ="{Binding}"/>
        <MenuItem Command ="{x:Static ssui:SpreadsheetCommands.HideSheet}" CommandParameter ="{Binding}"/>
        <MenuItem Command ="{x:Static ssui:SpreadsheetCommands.UnhideSheet}" CommandParameter ="{Binding}"/>
    </ContextMenu>


    <ControlTemplate TargetType ="{x:Type ContentControl}" x:Key="worksheetTabButtonTemplate">
        <Grid Margin="0 0 0 -12">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="5"/>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="18"/>
            </Grid.ColumnDefinitions>
            <Rectangle Fill ="{TemplateBinding Background}" Grid.Column="1" Margin="-0.5 0 -0.5 0" Height="18" VerticalAlignment="Top"/>
            <Path Data="M -0.5,0 L 5,0 L 5,18 L -0.5 18 Z" Fill ="{TemplateBinding Background}" Grid.Column="0" >
            </Path>
            <Path Data="M -0.5,0 L 18,0 L 0,18 L -0.0, 0" Fill ="{TemplateBinding Background}" Grid.Column="2">
            </Path>

            <Border BorderBrush="{DynamicResource {x:Static ss:SpreadsheetBrushes.SheetTabBorderBrushKey}}" BorderThickness="0 0 0 1" Grid.Column ="1">
                <ContentPresenter Name="cp" Content ="{TemplateBinding Content}" ContentTemplate="{StaticResource worksheetTabTemplate}" Margin=" 2 0 2 -2" />
            </Border>
        </Grid>
    </ControlTemplate>
    <Style TargetType="{x:Type Button}" x:Key="tabButtonStyle">
        <EventSetter Event="PreviewMouseDown" Handler="OnSheetTabButtonPreviewMouseDown"></EventSetter>
    </Style>

    <Style TargetType="{x:Type ListBoxItem}" x:Key="sheetTab">
        <Setter Property="Focusable" Value="False"/>
        <!-- <Setter Property="Background" Value="{StaticResource normalTab}"/> -->
        <Setter Property="Background">
            <Setter.Value>
                <MultiBinding Converter="{x:Static Internals:SpreadsheetConverters.ColorToTabBackgroundConverter}" >
                    <Binding Path="Properties.TabColor" />
                    <Binding Path="Workbook.Theme.ColorScheme"></Binding>
                    <Binding Source="default"></Binding>
                </MultiBinding>
            </Setter.Value>
        </Setter>
        <Setter Property="Foreground">
            <Setter.Value>
                <MultiBinding Converter="{x:Static Internals:SpreadsheetConverters.ColorToTabForegroundConverter}" >
                    <Binding Source="{StaticResource {x:Static oui:OfficeBrushes.TextForegroundKey}}"></Binding>
                    <Binding Path="Properties.TabColor" />
                    <Binding Path="Workbook.Theme.ColorScheme"></Binding>
                    <Binding Source="default"></Binding>
                </MultiBinding>
            </Setter.Value>
        </Setter>
        <Setter Property="Visibility" Value="{Binding Path=IsVisible, Converter={x:Static ssui:BooleanToVisibilityConverter.InstanceHidden}}"/>
        <Setter Property="Margin" Value="0 1 -12 0"/>
        <Setter Property="TextElement.FontFamily" Value="Calibri"/>
        <Setter Property="TextElement.Foreground" Value="{DynamicResource {x:Static oui:OfficeBrushes.TextForegroundKey}}"/>
        <Setter Property="TextElement.FontSize" Value="14"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType ="{x:Type ListBoxItem}">
                    <Grid>
                        <ContentControl Template="{StaticResource worksheetTabButtonTemplate}" 
                                        Foreground="Transparent"
                                        Background ="{TemplateBinding Background}" 
                                        HorizontalAlignment="Stretch">
                        </ContentControl>
                        <ContentControl Template="{StaticResource worksheetTabButtonTemplate}" Visibility="Hidden" 
                                        Content="{TemplateBinding Content}" 
                                        Name="gradient" Foreground="Transparent" HorizontalAlignment="Stretch" IsHitTestVisible="False"
                                        Background="{TemplateBinding Background}">
                            <ContentControl.Resources>
                                <SolidColorBrush Color="Transparent" x:Key="{x:Static oui:OfficeBrushes.TextForegroundKey}"></SolidColorBrush>
                            </ContentControl.Resources>
                        </ContentControl>
                        <ContentControl Template="{StaticResource worksheetTabButtonTemplate}" 
                                        Foreground="Transparent"
                                        
                                        Content="{TemplateBinding Content}" Background="{TemplateBinding Background}" HorizontalAlignment="Stretch">
                            <ContentControl.Resources>
                                <SolidColorBrush Color="Transparent" x:Key="{x:Static oui:OfficeBrushes.TextForegroundKey}"></SolidColorBrush>
                            </ContentControl.Resources>
                        </ContentControl>

                        <Button Style="{StaticResource tabButtonStyle}" 
                                Template="{StaticResource worksheetTabButtonTemplate}" Content="{TemplateBinding Content}"
                                DataContext="{TemplateBinding Content}"
                  Background="Transparent" Command="{x:Static ssui:WorkbookNavigationCommands.MoveTo}"
                                CommandParameter="{TemplateBinding Content}"
                  FocusVisualStyle="{x:Null}" Name="button" Focusable="False"  TextElement.Foreground="{TemplateBinding Foreground}"
                                 Internals:AdditionalTags.InheritedTag="{Binding RelativeSource={RelativeSource Self}}"
                                 Internals:AdditionalTags.Tag1="{DynamicResource {x:Static ss:SpreadsheetWindowComponents.SheetTabsContextMenuKey}}"
                    Internals:AdditionalTags.Tag2="{DynamicResource {x:Static ss:SpreadsheetWindowComponents.DefaultSheetTabsContextMenuKey}}">
                            <Button.ContextMenu>
                                <MultiBinding Converter="{x:Static Internals:FirstNonNullConverter.Instance}">
                                    <Binding RelativeSource="{RelativeSource Self}" Path="(Internals:AdditionalTags.Tag1)"></Binding>
                                    <Binding RelativeSource="{RelativeSource Self}" Path="(Internals:AdditionalTags.Tag2)"></Binding>
                                </MultiBinding>
                            </Button.ContextMenu>
                        </Button>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="true">
                            <Setter TargetName="gradient" Property="Visibility" Value="Visible"></Setter>
                        </Trigger>
                        <Trigger Property="IsSelected" Value="true">
                            <Setter TargetName="gradient" Property="Visibility" Value="Hidden"></Setter>
                        </Trigger>
                    </ControlTemplate.Triggers>

                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Style.Triggers>
            <Trigger Property ="IsMouseOver" Value="False">
                <Setter Property="Foreground">
                    <Setter.Value>
                        <MultiBinding Converter="{x:Static Internals:SpreadsheetConverters.ColorToTabForegroundConverter}" >
                            <Binding Source="{StaticResource {x:Static oui:OfficeBrushes.TextForegroundKey}}"></Binding>
                            <Binding Path="Properties.TabColor" />
                            <Binding Path="Workbook.Theme.ColorScheme"></Binding>
                            <Binding Source="default"></Binding>
                        </MultiBinding>
                    </Setter.Value>
                </Setter>
            </Trigger>
            <Trigger Property ="IsMouseOver" Value="True">
                <Setter Property="Background">
                    <Setter.Value>
                        <MultiBinding Converter="{x:Static Internals:SpreadsheetConverters.ColorToTabBackgroundConverter}" >
                            <Binding Path="Properties.TabColor" />
                            <Binding Path="Workbook.Theme.ColorScheme"></Binding>
                            <Binding Source="hover"></Binding>
                        </MultiBinding>
                    </Setter.Value>
                </Setter>
                <Setter Property="Foreground">
                    <Setter.Value>
                        <MultiBinding Converter="{x:Static Internals:SpreadsheetConverters.ColorToTabForegroundConverter}" >
                            <Binding Source="{StaticResource {x:Static oui:OfficeBrushes.TextForegroundKey}}"></Binding>
                            <Binding Path="Properties.TabColor" />
                            <Binding Path="Workbook.Theme.ColorScheme"></Binding>
                            <Binding Source="hover"></Binding>
                        </MultiBinding>
                    </Setter.Value>
                </Setter>
            </Trigger>
            <Trigger Property ="IsSelected" Value="True">
                <Setter Property="TextElement.FontWeight" Value ="Bold"/>
                <Setter Property="Margin" Value ="0 0 -12 0"/>
                <!--<Setter Property="Panel.ZIndex" Value ="100"/> -->
                <Setter Property="Internals:ReverseZIndexStackPanel.ZTop" Value ="true"/>
                <Setter Property="Background">
                    <Setter.Value>
                        <MultiBinding Converter="{x:Static Internals:SpreadsheetConverters.ColorToTabBackgroundConverter}" >
                            <Binding Path="Properties.TabColor" />
                            <Binding Path="Workbook.Theme.ColorScheme"></Binding>
                            <Binding Source="selected"></Binding>
                        </MultiBinding>
                    </Setter.Value>
                </Setter>
                <Setter Property="Foreground">
                    <Setter.Value>
                        <MultiBinding Converter="{x:Static Internals:SpreadsheetConverters.ColorToTabForegroundConverter}" >
                            <Binding Source="{StaticResource {x:Static oui:OfficeBrushes.TextForegroundKey}}"></Binding>
                            <Binding Path="Properties.TabColor" />
                            <Binding Path="Workbook.Theme.ColorScheme"></Binding>
                            <Binding Source="selected"></Binding>
                        </MultiBinding>
                    </Setter.Value>
                </Setter>
            </Trigger>
        </Style.Triggers>
    </Style>

    <Style TargetType="{x:Type Button}" x:Key="sheetNavigationButton">
        <Setter Property="Background" Value="{DynamicResource {x:Static ss:SpreadsheetBrushes.SheetTabBackgroundKey}}"/>
        <Setter Property="Margin" Value="0"/>
        <Setter Property="Width" Value="16"/>
        <Setter Property="VerticalContentAlignment" Value="Center"/>
        <Setter Property="HorizontalContentAlignment" Value="Center"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType ="{x:Type Button}">
                    <Grid >
                        <Border BorderBrush="{DynamicResource {x:Static ss:SpreadsheetBrushes.SheetTabBorderBrushKey}}" BorderThickness="0" Background="{TemplateBinding Background}" Name="bd">

                            <ContentPresenter Content ="{TemplateBinding Content}" 
                                
                                VerticalAlignment="Center"
                                HorizontalAlignment="Center">
                            </ContentPresenter>
                        </Border>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property ="IsMouseOver" Value="True">
                            <Setter Property="Background" Value="{DynamicResource {x:Static ss:SpreadsheetBrushes.SheetTabSelectedBackgroundKey}}"/>
                            <Setter Property="BorderThickness" Value="1" TargetName="bd"/>
                        </Trigger>

                    </ControlTemplate.Triggers>
                </ControlTemplate>

            </Setter.Value>
        </Setter>
        <Style.Triggers>
            <Trigger Property ="IsPressed" Value="True">
                <Setter Property="Background" Value="{DynamicResource {x:Static ss:SpreadsheetBrushes.SheetTabSelectedBackgroundKey}}"/>
            </Trigger>
        </Style.Triggers>
    </Style>
    <Style TargetType="{x:Type Button}" x:Key="sheetButton">
        <Setter Property="Focusable" Value="False"/>
        <Setter Property="Background" Value="{DynamicResource {x:Static ss:SpreadsheetBrushes.SheetTabBackgroundKey}}"/>
        <Setter Property="Margin" Value="0"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType ="{x:Type Button}">
                    <Grid Margin="-12 0 0 0">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="4"/>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="{TemplateBinding ActualHeight}"/>
                        </Grid.ColumnDefinitions>
                        <Path Data="M -0.5,0 L 4,0 L 4,16 L -0.5, 16 Z" Fill ="{TemplateBinding Background}" Grid.Column="0">
                        </Path>
                        <Rectangle Width="12" Fill="{TemplateBinding Background}"
                       Stroke="{DynamicResource {x:Static ss:SpreadsheetBrushes.SheetTabBorderBrushKey}}" RadiusX="2" RadiusY="2" Margin="0 0  -2 0">
                            <Rectangle.RenderTransform>
                                <SkewTransform AngleX="15"/>
                            </Rectangle.RenderTransform>
                        </Rectangle>
                        <Path Data="M -0.5,0 L 16,0 L 0,16 L -0.0, 0" Fill ="{TemplateBinding Background}" Grid.Column="2">
                        </Path>

                        <Rectangle Fill ="{TemplateBinding Background}" Grid.Column="1"/>
                        <Border BorderBrush="{DynamicResource {x:Static ss:SpreadsheetBrushes.SheetTabBorderBrushKey}}" BorderThickness="0 0 0 1" Grid.Column ="1">

                            <ContentPresenter Content ="{TemplateBinding Content}" Margin=" 2 0 2 0">
                            </ContentPresenter>
                        </Border>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Style.Triggers>
            <Trigger Property ="IsMouseOver" Value="True">
                <Setter Property="Background" Value="{DynamicResource {x:Static ss:SpreadsheetBrushes.SheetTabSelectedBackgroundKey}}"/>
            </Trigger>
        </Style.Triggers>
    </Style>


</ResourceDictionary>